package Sort;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:52
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {4,3,2,6,8,1,9,10,5};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void shellSort(int[] arr){
        //模拟一次
        for (int gap = arr.length/2;gap > 0; gap/=2) {
           for (int i = gap; i < arr.length; i++){
               int j = i;
               int temp = arr[j];
               if (arr[j - gap] > temp){//开始插入排
                   while ((j - gap) >= 0 && arr[j - gap] > temp){
                       arr[j] = arr[j-gap];
                       j -= gap;
                   }
                   arr[j] = temp;
               }
           }
        }
    }
}
